package example

import (
	"fmt"
	time2 "time"
)

type LoaderBalancer struct {
	channel1 chan Client
	channel2 chan Client
	channel3 chan Client
	channel4 chan Client
}

type Client struct {
	content string
	time    time2.Time
}

func execute(client *Client) {
	fmt.Printf("%s - handle the %s\n", client.time.Format("2006-01-02T15:04:05-07:00"), client.content)
}

func handle(loader *LoaderBalancer) {
	select {
	case v := <-loader.channel1:
		execute(&v)
	case v := <-loader.channel2:
		execute(&v)
	case v := <-loader.channel3:
		execute(&v)
	case v := <-loader.channel4:
		execute(&v)
	default:
		fmt.Println("no client")
	}
}

func mockLoadBalance() {
	// prepare client
	client1 := Client{"request1", time2.Now()}
	client2 := Client{"request2", time2.Now()}
	client3 := Client{"request3", time2.Now()}
	client4 := Client{"request4", time2.Now()}

	channel1 := make(chan Client, 4)
	channel1 <- client1
	channel2 := make(chan Client, 4)
	channel2 <- client2
	channel3 := make(chan Client, 4)
	channel3 <- client3
	channel4 := make(chan Client, 4)
	channel4 <- client4

	loader := LoaderBalancer{channel1, channel2, channel3, channel4}

	handle(&loader)
}
